package com.ajcorp.common;

import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import org.supercsv.exception.NullInputException;
import org.supercsv.io.CsvBeanWriter;
import org.supercsv.prefs.CsvPreference;

import com.ajcorp.main.SimplePOJO;

public class Helper {

	public static int generateCSV(List simplepojolist) throws IOException{
		
		boolean displayheader = false;
		//CsvBeanWriter writer = new CsvBeanWriter(new PrintWriter(System.out), CsvPreference.STANDARD_PREFERENCE);
		CsvBeanWriter writer = new CsvBeanWriter(new FileWriter("/home/abhishekj/Desktop/Test.csv"), CsvPreference.STANDARD_PREFERENCE);
		try
		{
			final String[] nameMapping = new String[]{"name","age","address","telephone"};
			
			if(displayheader)
				writer.writeHeader(nameMapping);
            
		
			for (Object element : simplepojolist) {
				writer.write(element, nameMapping);
            }
        }
		catch(NullInputException nie)
		{
			System.out.println("do nothing");
			
		}
        catch(Exception e)
        {
        	e.printStackTrace();
        }
        finally {
            writer.close();
        }
		return 0;
	}
}
